//
//  WXPBankCardCell.m
//  MexicoLoan
//
//  Created by WXP on 2025/3/11.
//
//

#import "WXPBankCardCell.h"

@interface WXPBankCardCell ()

@end

@implementation WXPBankCardCell

#pragma mark - lazy
- (UIView *)viewBack
{
    if (_viewBack == nil) {
        _viewBack = [UIView  new];
        _viewBack.backgroundColor = COLOR_WHITE;
        [GlobalMethod setRoundView:_viewBack color:[UIColor clearColor] numRound:16 width:0];
        _viewBack.userInteractionEnabled = true;
    }
    return  _viewBack;
}
- (UIImageView *)imageLogo{
    if (_imageLogo == nil) {
        _imageLogo = [UIImageView new];
        _imageLogo.widthHeight = XY(36, 18);
    }
    return _imageLogo;
}
- (UIImageView *)imageLogoBack{
    if (_imageLogoBack == nil) {
        _imageLogoBack = [UIImageView new];
        _imageLogoBack.alpha = 0.03;
    }
    return _imageLogoBack;
}
- (UILabel *)labelName{
    if (_labelName == nil) {
        _labelName = [UILabel new];
        _labelName.textColor = COLOR_CONTENT;
        _labelName.fontNum = 14;
    }
    return _labelName;
}
- (UILabel *)labelNumber{
    if (_labelNumber == nil) {
        _labelNumber = [UILabel new];
        _labelNumber.textColor = COLOR_BLACK;
        _labelNumber.font = [UIFont boldSystemFontOfSize:24];
    }
    return _labelNumber;
}
-(UIButton *)btnEdit{
    if (_btnEdit == nil) {
        _btnEdit = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btnEdit setImage:[UIImage imageNamed:@"icon-bank-card-edit"] forState:UIControlStateNormal];
        _btnEdit.widthHeight = XY(18+20+20, 18+20+20);
        WEAKSELF
        [_btnEdit setNoRepeatActionWithInterval:3 action:^(UIButton * _Nonnull button) {
            [NSObject clickFeedback];
            [weakSelf.btnEdit addClickAnimate];
            if(weakSelf.blockEditBank){
                weakSelf.blockEditBank(weakSelf.modelBankCard);
            }
        }];
    }
    return _btnEdit;
}


#pragma mark - 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor clearColor];
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUpView];
    }
    return self;
}

- (void)setUpView{
    [self.contentView addSubview:self.viewBack];
    [self.viewBack addSubview:self.imageLogoBack];
    [self.viewBack addSubview:self.imageLogo];
    [self.viewBack addSubview:self.labelName];
    [self.viewBack addSubview:self.labelNumber];
    [self.viewBack addSubview:self.btnEdit];
}

#pragma mark - 刷新cell
- (void)resetCellWithModel:(ModelBankCard *)model{
    self.modelBankCard = model;
    self.viewBack.widthHeight = XY(SCREEN_WIDTH-LEFT_MARDIN*2, 0);
    
    self.imageLogo.image = [UIImage imageNamed:@"icon-bank-card-logo"];
    self.imageLogo.leftTop = XY(20, 20);
    
    NSDictionary * dataDic = [GlobalMethod exchangeStringToDic:readStr(model.data)];
    [self.labelName fitTitle:[dataDic stringValueForKey:@"bankName"] variable:0];
    self.labelName.leftCenterY = XY(self.imageLogo.right+8, self.imageLogo.centerY);
    
    [self.labelNumber fitTitle:[dataDic stringValueForKey:@"bankCard"] variable:0];
    self.labelNumber.leftTop = XY(self.imageLogo.left, self.imageLogo.bottom+20);
    
    self.btnEdit.rightTop = XY(self.viewBack.width, self.labelNumber.bottom+6);
    
    self.viewBack.height = self.btnEdit.bottom;
    self.imageLogoBack.image = self.imageLogo.image;
    self.imageLogoBack.widthHeight = XY(self.viewBack.height/3*4, self.viewBack.height/3*2);
    self.imageLogoBack.rightBottom = XY(self.viewBack.width, self.viewBack.height);
    
    self.viewBack.centerXTop = XY(SCREEN_WIDTH/2, 0);
    self.height = self.viewBack.bottom+LEFT_MARDIN;
}

@end
